package com.woniuxy01;

import java.util.Scanner;

/**
 * @author 作者
 * @create 2025-10-22 14:47
 */
public class Test11 {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int result=0;
        System.out.println("输入运算符+ - * /");
        char operator=scanner.next().charAt(0);
        System.out.println("输入一个运算数");
        int numA=scanner.nextInt();
        System.out.println("输入一个运算数");
        int numB=scanner.nextInt();
        //定义一个标志变量，就是一个布尔值
        //flag:true,代表运算符有效;false,代表运算符无效;
        boolean flag=true;
        if(operator=='+'){
            result=numA+numB;
        }else if(operator=='-'){
            result=numA-numB;
        }else if(operator=='*'){
            result=numA*numB;
        }else if(operator=='/'){
            if (numB!=0) {
                result=numA/numB;
            }
        }else{
            flag=false;
        }

        //统一输出(运算结果，/0,运算符无效)
        //if(operator=='+' || operator=='-' || operator=='*' || operator=='/')
        if(flag){
            if( operator=='/' && numB==0){
                System.out.println("/0，不能计算");
            }else{
                System.out.println(""+numA+operator+numB+"="+result);
            }
        }else{
            System.out.println("无效运算符，无法计算");
        }
    }
}
